/**
 * 
 */
package xiaojian.toolkit.ebus.unit;

import xiaojian.toolkit.util.Pair;

/**
 * @author Marvin.Ma
 *
 */
public abstract class AbstractUnitBuilder implements UnitBuilder {

	private String name;
	
	public AbstractUnitBuilder(String name) {
		this.name = name;
	}
	
	/* (non-Javadoc)
	 * @see stc.skymobi.ebus.unit.UnitBuilder#createUnit(stc.skymobi.ebus.unit.UnitSource)
	 */
	public Pair<EventUnit, String> createUnit(UnitSource source) {
		EventUnit unit = createUnitImpl();
		if ( null == unit ) {
			return Pair.of(null, "[" + name + "] : can't instantiated unit source { " 
					+ source.getName() + "}");
		}
		if ( unit instanceof UnitSourceAware ) {
			((UnitSourceAware)unit).setUnitSource(source);
		}
		return Pair.of(unit, null);
	}

    protected abstract EventUnit createUnitImpl();
}
